//
//  SSSRecommendController.m
//  SSSMerchant
//
//  Created by Darker on 2017/3/23.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSRecommendController.h"
#import "ZDGenerateQRCodeVC.h"
#import "ZDQRCodeTool.h"
#import "SSSRecommendRecordController.h"
#import "ZDShareView.h"


@interface SSSRecommendController ()
{
    ZDShareView *shareView;
    
}
@end

@implementation SSSRecommendController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.title = @"推荐";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIImageView *bgImageView =[[UIImageView alloc]init];
    bgImageView.image = [UIImage imageNamed:@"bg"];
    bgImageView.frame = self.view.frame;
    bgImageView.userInteractionEnabled = YES;
    [self.view addSubview:bgImageView];
    //添加二维码背景图
    UIImageView *rcodeImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"WechatIMG4.png"]];
    rcodeImageView.userInteractionEnabled = YES;
    [bgImageView addSubview:rcodeImageView];
    rcodeImageView.sd_layout
    //.centerXEqualToView(bgImageView)
    .topSpaceToView(bgImageView,HeigthIos6CompeteWithCurrent(141))
    .leftSpaceToView(bgImageView,WidthIos6CompeteWithCurrent(84))
    .rightSpaceToView(bgImageView,WidthIos6CompeteWithCurrent(85))
    //.heightIs(HeigthIos6CompeteWithCurrent(300));
    .bottomSpaceToView(bgImageView,HeigthIos6CompeteWithCurrent(215));
    rcodeImageView.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    rcodeImageView.layer.masksToBounds = YES;
    
    
    //添加按钮
    UIButton *shareBtn = [[UIButton alloc]init];
    [shareBtn addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchDown];
    [rcodeImageView addSubview:shareBtn];
    shareBtn.sd_layout
    .bottomSpaceToView(rcodeImageView,0)
    .leftSpaceToView(rcodeImageView,0)
    .rightSpaceToView(rcodeImageView,0)
    .heightIs(HeigthIos6CompeteWithCurrent(60));
    
    
    
    
    // 1、借助UIImageView显示二维码
    UIImageView *imageView = [[UIImageView alloc] init];
    [rcodeImageView addSubview:imageView];
    imageView.backgroundColor = [UIColor yellowColor];
    imageView.sd_layout
    .topSpaceToView(rcodeImageView,HeigthIos6CompeteWithCurrent(29))
    .centerXEqualToView(rcodeImageView)
    .widthIs(WidthIos6CompeteWithCurrent(159))
    .heightIs(HeigthIos6CompeteWithCurrent(164));
    
    
    //CGFloat imageViewW = rcodeImageView.frame.size.width - WidthIos6CompeteWithCurrent(10)*2;
    
    // 2、将CIImage转换成UIImage，并放大显示
    imageView.image = [ZDQRCodeTool ZD_generateWithDefaultQRCodeData:@"https://github.com/kingsic" imageViewWidth:159];
    
    //导航栏按钮
    //self.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithTitle:@"记录" color:ThemeGreenColor target:self action:@selector(toRecommendRecordController)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemRightTitleColorWithImage:@"icon_record" highImage:nil title:nil color:nil target:self action:@selector(toRecommendRecordController)];
    
}
- (void)shareBtnClick{
    
        shareView = [[ZDShareView alloc] initWithFrame:CGRectMake(0, 0, KSCREEN_Width, KSCREEN_Height) dataUrl:nil imageUrl:nil textTitle:@"分享" content:nil startVc:self];
        [self.view addSubview:shareView];
    
}
- (void)toRecommendRecordController{
    
    SSSRecommendRecordController *RecommendRecordVc = [[SSSRecommendRecordController alloc]init];
    [self.navigationController pushViewController:RecommendRecordVc animated:YES];

    
}
@end
